﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Styx.CommonBot.Routines;
using Styx.TreeSharp;
using Styx;
using Styx.CommonBot;
using Action = Styx.TreeSharp.Action;
using Styx.Common;
using System.Windows.Media;

namespace Gelu_Ossium
{
    public partial class GO : CombatRoutine
    {
        #region Startup
        public override string Name { get { return "GO"; } }
        public override WoWClass Class { get { return WoWClass.DeathKnight; } }
        #endregion

        #region Initialize
        private Composite _buffs, _combat;
        public override Composite PreCombatBuffBehavior { get { return _buffs; } }
        public override Composite CombatBuffBehavior { get { return _buffs; } }
        public override Composite CombatBehavior { get { return _combat; } }
        public override void Initialize() { _buffs = CreateBuffs(); _combat = CreateCombat(); }
        #endregion

        #region Rotations
        Composite CreateBuffs()
        {
            return new PrioritySelector(
                Cast("Horn of Winter", ret => !StyxWoW.Me.HasAura("Horn of Winter")),
                Cast("Chains of Ice", ret => !StyxWoW.Me.CurrentTarget.HasAura("Chains of Ice")));
        }
        Composite CreateCombat()
        {
            return new PrioritySelector(
                new Decorator(ret => StyxWoW.Me.CurrentTarget.DistanceSqr <= 5 * 5,
                    new PrioritySelector(
                        Cast("Mind Freeze", ret => StyxWoW.Me.CurrentTarget.IsCasting && StyxWoW.Me.CurrentTarget.CanInterruptCurrentSpellCast),
                        Cast("Outbreak"),
                        Cast("Plague Strike", ret => SpellManager.Spells["Outbreak"].Cooldown && !StyxWoW.Me.CurrentTarget.HasAura("Blood Plague")),
                        Cast("Howling Blast", ret => SpellManager.Spells["Outbreak"].Cooldown && !StyxWoW.Me.CurrentTarget.HasAura("Frost Fever")),
                        Cast("Soul Reaper", ret => StyxWoW.Me.CurrentTarget.HealthPercent < 35),
                        Cast("Howling Blast", ret => StyxWoW.Me.HasAura("Freezing Fog")),
                        //Cast("Frost Strike", ret => StyxWoW.Me.CurrentRunicPower >= 80 || StyxWoW.Me.HasAura("Killing Machine")), //<~ DW
                        //Cast("Obliterate", ret => StyxWoW.Me.FrostRuneCount == 2 && StyxWoW.Me.UnholyRuneCount == 2 || StyxWoW.Me.DeathRuneCount == 2 || StyxWoW.Me.HasAura("Killing Machine") && StyxWoW.Me.CurrentRunicPower < 20), //<~ DW
                        Cast("Obliterate", ret => StyxWoW.Me.CurrentRunicPower < 76 || StyxWoW.Me.HasAura("Killing Machine")),
                        //Cast("Howling Blast"), //<~ DW
                        Cast("Frost Strike"),
                        Cast("Horn of Winter"))),
                new Decorator(ret => StyxWoW.Me.CurrentTarget.DistanceSqr > 5 * 5 && StyxWoW.Me.CurrentTarget.DistanceSqr <= 30 * 30,
                    new PrioritySelector(
                        Cast("Chains of Ice", ret => !StyxWoW.Me.CurrentTarget.HasAura("Chains of Ice")),
                        Cast("Outbreak"),
                        Cast("Howling Blast", ret => SpellManager.Spells["Outbreak"].Cooldown && !StyxWoW.Me.CurrentTarget.HasAura("Frost Fever")),
                        Cast("Howling Blast", ret => StyxWoW.Me.HasAura("Freezing Fog")),
                        //Cast("Howling Blast"), //<~ DW
                        Cast("Horn of Winter"))));
        }
        #endregion

        #region Cast Method
        private delegate T Selection<out T> (object context);
        Composite Cast(string spell, Selection<bool> reqs = null)
        {
            return new Decorator(ret => ((reqs != null && reqs(ret)) || (reqs == null)) && SpellManager.CanCast(spell),
                new Action(delegate { SpellManager.Cast(spell); Logging.Write(Colors.DarkOrange, "Casting: " + spell); }));
        }
        #endregion
    }
}
